#
# explosion.py -- explosion object
# 
# author: Tom "Knio" Flanagan
#         knio@h4xn3t.net
#         theknio@gmail.com
#         irc.freenode.net - Knio - #python #pygame #py
#
# this file released under Public Domain
#

import object
from constants import *




class Explosion(object.Object):
    rate={  0:1.00,
            1:1.00,
            2:0.90,
            3:0.80,
            4:0.65,
            5:0.50,
            6:0.35,
            7:0.20,
            8:0.10,
            9:0.00
            } 

    
    def __init__(self, battle, **kwargs):
        object.Object.__init__(self, battle, **kwargs)
        self.currentsize = 0
        self.power = 1.0

    def poll(self):
        if self.currentsize > self.size: return self.die()
        self.currentsize += 1.

        self.power = 1-self.currentsize/self.size
        for [d], i in self.data:
            c = abs(d-self.currentsize)
            force = int(c/(self.size/5.))
            if force >= 10: break
            damage  = self.rate[force] * self.power * self.size
            push    = self.rate[force] * self.power * self.size
            self.damage(i,  damage/2.)
            if d > 2:   self.push(i,    push/50.)

    def damage(self, object, damage):
        object.hit(self, damage)

    def push(self, object, push):
        angle = self.angle(object)
        start = object.coordinates(object.h+PI, object.s)
        stop  = object.coordinates(angle, push)
        object.s = start.distance(stop)
        object.h = start.angle(stop)
            
    def die(self):
        self.state = 0
        self.battle.remove(self)
            
        
